'use strict';

/**
 * @ngdoc function
 * @name magisterkaGuiApp.controller:AlgorithmTournamentCtrl
 * @description
 * # AlgorithmTournamentCtrl
 * Controller of the magisterkaGuiApp
 */
angular.module('magisterkaGuiApp')
  .controller('AlgorithmTournamentCtrl', function ($scope, $log) {


      $scope.init = function () {
        $log.debug('alg race inited');
        $log.debug(event);
        $scope.$watch('event', function (newValue, oldValue) {
          var results = createDisplayResults(newValue);
          $scope.display = {
            results: results.slice(25,35)
          }
        });
      }

      function createDisplayResults(event) {

        var results = [];
        angular.forEach(event.algorithmState.peopleProgresses, function (progressData) {
          angular.forEach(event.people, function (personData) {
            if (progressData.id == personData.id) {
              results.push({
                id: personData.id,
                name: personData.name,
                profileImageUrl: personData.profileImageUrl,
                percentFinished: progressData.percentFinished ? progressData.percentFinished : 0
              });

            }
          });
        });

        return results;

      }


    });
